package com.gientech.madp.sm2.controller;

import cn.hutool.json.JSONObject;
import com.gientech.madp.sm2.service.SM4Service;
import com.gientech.madp.sm2.utils.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @Author smile_ZhongXuan
 * @Date 2021/11/1 14:30
 * @Version 1.0
 */
@RestController
@AllArgsConstructor
@RequestMapping("/sm4")
@Api(value = "api", tags = "SM4加解密签名")
public class SM4Controller {

    private final SM4Service sm4Service;

    /**
     * SM4加密
     * @param security
     * @param jsonObject
     * @return
     */
    @PostMapping("/encrypt")
    @ApiOperation(value = "SM4加密")
    public R encrypt(@RequestHeader String security, @RequestBody JSONObject jsonObject){
        return sm4Service.encrypt(security,jsonObject);
    }

    /**
     * SM4解密
     * @param security
     * @param jsonObject
     * @return
     */
    @PostMapping("/decrypt")
    @ApiOperation(value = "SM4解密")
    public R decrypt(@RequestHeader String security,  @RequestBody Map<String, Object> jsonObject){
        return sm4Service.decrypt(security,jsonObject);
    }

}
